package com.itheima_04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class ServerTest1 {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10086);
        FileOutputStream fos;
        while (true) {
            Socket accept = ss.accept();
            BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
            fos = new FileOutputStream("C:\\Users\\wfsxy\\Desktop\\新建文件夹\\"+ UUID.randomUUID() +".jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            byte[] bytes = new byte[1024];
            int len;
            while ((len = bis.read(bytes))!=-1){
                bos.write(bytes,0,len);
                bos.flush();
            }
            OutputStream os = accept.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            BufferedWriter bw = new BufferedWriter(osw);
            bw.write("已上传");
            bw.newLine();
            bw.flush();
            accept.shutdownOutput();
        }
        //fos.close();
        //ss.close();

    }
}
